import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/utils/x_load_image.dart';

import 'onnx_talk_bar_tools_view.dart';

///
/// 键盘/语音切换按钮视图
///
class OnnxToggleButtonsView extends StatelessWidget {
  final ValueNotifier<ChatInputMode> inputModeNotifier;
  final ValueChanged<ChatInputMode>? onToggle;

  const OnnxToggleButtonsView({
    super.key,
    required this.inputModeNotifier,
    this.onToggle,
  });

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<ChatInputMode>(
      valueListenable: inputModeNotifier,
      builder: (context, mode, child) {
        return GestureDetector(
          onTap: () => _handleToggle(),
          child: Container(
            width: 36,
            height: 36,
            margin: const EdgeInsets.only(bottom: 2),
            child: XAssetsImage.load(
              mode == ChatInputMode.keyboard ? 'icon_agent_voice' : 'icon_agent_keyboard',
            ),
          ),
        );
      },
    );
  }

  void _handleToggle() {
    final newMode = inputModeNotifier.value == ChatInputMode.keyboard ? ChatInputMode.voice : ChatInputMode.keyboard;
    inputModeNotifier.value = newMode;
    onToggle?.call(newMode);
  }
}
